import axios from "axios";
import { Pageable, Pagination } from '@/types/global'
import { DictDto, DictItemVo, DictParam, DictVo } from '@/types/modules/system'

const contentPath = '/system/dict'

export function create(dictDto: DictDto) {
  return axios.post<boolean>(`${contentPath}`, dictDto)
}

export function addItem(id: number, dictItemDto: DictItemVo) {
  return axios.post(`${contentPath}/${id}/item`, dictItemDto)
}

export function update(dictDto: DictDto) {
  return axios.put<boolean>(`${contentPath}`, dictDto)
}

export function deleteById(id: number) {
  return axios.delete<boolean>(`${contentPath}/${id}`)
}

export function findById(id: number) {
  return axios.get<DictVo>(`${contentPath}/${id}`)
}

export function listWithPagination(pageable: Pageable, param: DictParam) {
  return axios.get<Pagination<DictVo>>(`${contentPath}/pagination`, {
    params: {
      ...pageable,
      ...param
    }
  })
}

export function findAllItemByDictId(id: number) {
  return axios.get<DictItemVo[]>(`${contentPath}/${id}/item`)
}
